# 每次代码的编写都是对自己的考验
# 我爱打代码，代码使我快乐
# 布里斯班十年之约
# 此刻： 15:42
import torch
import torch.nn as nn
import torch.nn.functional as F

"""
Actor: 输入当前的状态s，输出当前应该执行的行动action
"""
class Actor(nn.Module):
    def __init__(self, state_dim, action_dim):
        super().__init__()
        self.linear1 = nn.Linear(state_dim, 256)
        self.linear2 = nn.Linear(256, 64)
        self.linear3 = nn.Linear(64, action_dim)

    def forward(self, state):
        y = F.relu(self.linear1(state))
        y = F.relu(self.linear2(y))
        y = torch.tanh(self.linear3(y))
        return y
    """
    Critic: 输入当前的状态以及经过Actor的判断的行动action，输出执行该action的价值value
    """
class Critic(nn.Module):
    def __init__(self, state_dim, action_dim):
        super().__init__()
        self.linear1 = nn.Linear(state_dim + action_dim, 256)
        self.linear2 = nn.Linear(256, 64)
        self.linear3 = nn.Linear(64, 1)

    def forward(self, state, action):
        x = torch.cat((state, action), dim=1)
        x = F.relu(self.linear1(x))
        x = F.relu(self.linear2(x))
        x = self.linear3(x)
        return x
